<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="callcpp" onclick="callcpp()">callcpp</button>
    <button onclick="getValue()">getValue</button>

    <script src="qwebchannel.js"></script>

    <script type="text/javascript">
        var webObj;

        // 创建Webchannel，与C++端建立连接
        new QWebChannel(qt.webChannelTransport, function (channel) {

                // 获取类的对象
                webObj = channel.objects.mytestclass;

                // 类的事件
                webObj.navStatusChanged.connect(function(arg){
                    alert("navStatusChanged: " + arg);
                });
            });

        function callcpp(){

            // 类的方法
            webObj.function1('this is a test');
        }

        function getValue(){

            // 类的属性值
            var status = webObj.navStatus;

            alert(status);
        }

        
    </script>
</body>
</html>